﻿<%@ Page Title="Planning" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="UsersList.aspx.cs" Inherits="APMAWebConsole.SettingsPart.UsersList" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Users List
    </h2>

    <asp:Button ID="btnAddUser" runat="server" Text="Add User" OnCommand="OnButtonCommand" CommandName="Add"/>
    <asp:Button ID="btnRemoveUser" runat="server" Text="Remove User" OnCommand="OnButtonCommand" CommandName="Remove" Visible="false"/>
    <asp:Button ID="btnEditUser" runat="server" Text="Edit User" OnCommand="OnButtonCommand" CommandName="Edit" Visible="false"/>
    <asp:Button ID="btnBackToList" runat="server" Text="Back to User List" OnCommand="OnButtonCommand" CommandName="BackToList" CausesValidation="False"/>
        
    <div id="divUsersGrid" runat="server">
        <p>
            <asp:Label ID="lblSelectedUser" runat="server" AssociatedControlID="txtSelectedUser" Text="Selected User ID:" Visible="false" />
            <asp:TextBox ID="txtSelectedUser" runat="server" CssClass="textEntry" Text="0" Visible="false" />
        </p>
        <asp:GridView ID="grdUsersList" runat="server" AutoGenerateColumns="false">
            <columns>
                <asp:BoundField HeaderText="ID" DataField="Id" />
                
                <asp:TemplateField HeaderText="" ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="btnEdit" runat="server" CausesValidation="false" Text="Edit" OnCommand="OnButtonCommand" CommandName="Select" CommandArgument='<%# Container.DataItemIndex + 1 %>'/>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="" ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="btnRemove" runat="server" CausesValidation="false" Text="X" OnCommand="OnButtonCommand" CommandName="Remove" CommandArgument='<%# Container.DataItemIndex + 1 %>'/>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:BoundField HeaderText="Name" DataField="Name" />
                <asp:BoundField HeaderText="Permission lvl" DataField="Access_id" />
            </columns>
        </asp:GridView>
    </div>
        
    <div id="divEditMode" runat="server">
        <p>
            <asp:Label ID="lblUserId" runat="server" AssociatedControlID="txtUserId">ID:</asp:Label>
            <asp:TextBox ID="txtUserId" runat="server" CssClass="textEntry"></asp:TextBox>
        </p>
        <p>
            <asp:Label ID="lblUserLogin" runat="server" AssociatedControlID="txtUserLogin">Login:</asp:Label>
            <asp:TextBox ID="txtUserLogin" runat="server" CssClass="textEntry"></asp:TextBox>
            <asp:RequiredFieldValidator id="rfvUserLogin" runat="server"
                                        ControlToValidate="txtUserLogin"
                                        ErrorMessage=" * User Login is a required field."
                                        ForeColor="Red"/>
            <br/>
            <asp:RegularExpressionValidator id="revUserLogin" runat="server" SetFocusOnError="True"
                                            ErrorMessage="User Login length must be between 3 and 50 characters, no whitespaces." Display="Dynamic"
                                            ControlToValidate="txtUserLogin" ValidationExpression="^[a-zA-Z0-9]{3,50}$"/>
        </p>
        <p>
            <asp:Label ID="lblUserPassword" runat="server" AssociatedControlID="txtUserPassword">Password:</asp:Label>
            <asp:TextBox ID="txtUserPassword" runat="server" CssClass="textEntry" TextMode="Password" ></asp:TextBox>
            <% if (IsEditMode && !IsUpdate) { %>
                <asp:RequiredFieldValidator ID="rfvUserPassword" runat="server"
                                            ControlToValidate="txtUserPassword"
                                            ErrorMessage="* You cannot create user with blank password"
                                            ForeColor="Red"/>
            <% }
               else
               { %>
                
            <% }%>
            <br/>
            <%-- <asp:RegularExpressionValidator id="revUserPassword" runat="server" SetFocusOnError="True"
                                            ErrorMessage="Make sure the password contains no white-space characters,<br> length more than 8 symbols, contains at least: one numeric character,<br> one upper case character, one lower case character (latin alphabet only)" Display="Dynamic"
                                            ControlToValidate="txtUserPassword" ValidationExpression="^(?=.*[^a-zA-Z])(?=.*[a-z])(?=.*[A-Z])\S{8,}$"/> --%>
            <asp:RegularExpressionValidator id="revUserPassword" runat="server" SetFocusOnError="True"
                                            ErrorMessage="Password must be 5 or more symbols length, contain only latin characters or numbers." Display="Dynamic"
                                            ControlToValidate="txtUserPassword" ValidationExpression="^[a-zA-Z0-9]{5,}$"/>
        </p>
        <p>
            <asp:Label ID="lblUserEmail" runat="server" AssociatedControlID="txtUserEmail">E-mail:</asp:Label>
            <asp:TextBox ID="txtUserEmail" runat="server" CssClass="textEntry"></asp:TextBox>
            <br/>
            <asp:RegularExpressionValidator id="revUserEmail" runat="server" SetFocusOnError="True"
                                            ErrorMessage="Please enter a valid e-mail" Display="Dynamic"
                                            ControlToValidate="txtUserEmail" ValidationExpression="^[-a-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*@(?:[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?\.)*(?:aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z][a-z])$"/>
        </p>
        <p>
            <asp:Label ID="lblUserAccessId" runat="server" AssociatedControlID="ddlUserAccessId">Permission level:</asp:Label>
            <asp:DropDownList ID="ddlUserAccessId" runat="server" />
            <asp:RequiredFieldValidator id="rfvUserAccessId" runat="server"
                                        ControlToValidate="ddlUserAccessId"
                                        ErrorMessage=" * User Permission level is a required field."
                                        ForeColor="Red"/>
        </p>

        <asp:Button ID="btnCreateUpdate" runat="server" Text="Save" OnCommand="OnButtonCommand" CommandName="SaveUpdate"/>

    </div>
</asp:Content>
